const app = getApp() 
var dateUtils = require('../utils/dateUtil.js');
Page({ 
 
  /** 
   * 页面的初始数据 
   */ 
  data: { 
      dateString: "", 
      spot: [],
      dataList:[],
      monthSkipRope:{},
      daySkipRope:{},
      selectIndex:0, 
      chooseData:"",
   
      totalPage:0, 
      pageNo:1, 
      pageSize:50, 
      isLoading:false, 
      allloaded: false, 
   
      isRefresh: 0,
      userData:{} ,
      defaultTime:dateUtils.formatTime(new Date()),
      ifClickChange:false
    }, 

    dateChange(e) { 
      if(!this.data.ifClickChange){
        return
      }
      console.log("选中日期变了,现在日期是", e.detail.dateString) 
      this.setData({
        chooseData:dateUtils.formatData(new Date(e.detail.dateString)),
      })
      this.getData(dateUtils.formatDataTime(new Date(e.detail.dateString))); 
    }, 
 
  /** 
   * 生命周期函数--监听页面加载 
   */ 
  onLoad(options) { 
    this.initUser()
    this.setData({ 
      pageNo:1, 
      dataList:[],
      //switchList:listData, 
      totalPage:0 
  }) 

  this.getData(dateUtils.formatDataTime(new Date())); 
},

initUser() {
  const userInfo = wx.getStorageSync('userData');
  const stuIndex = wx.getStorageSync('stuIndex');
  const data = userInfo.list[stuIndex]
  this.setData({
    defaultTime:dateUtils.formatTime(new Date()),
    userData: data,
    chooseData:dateUtils.formatData(new Date()),
  })
},

getData(strData){ 
//var vt = this.data.switchList[this.data.selectIndex] 
var data = { 
  pageNo:this.data.pageNo, 
  pageSize:this.data.pageSize, 
  startTime:strData,
	studentId:this.data.userData.studentId
} 

wx.showLoading({ 
  title: '数据加载中...', 
  icon: 'none', 
}) 

var that = this; 
console.log('历史任务1='+JSON.stringify(data)) 
app.api.skipRopeHistory(data).then(rest => { 
  wx.hideLoading() 
  this.setData({ 
    ifClickChange:true,
    isLoading:false 
  }) 
  
  if(rest&&rest.success){    
    console.log('历史任务='+JSON.stringify(rest)) 
    var dataList = []
    if(rest.data.flagList!=null){
      for(var i=0;i<rest.data.flagList.length;i++){
        if(rest.data.flagList[i].flag){
          dataList.push(rest.data.flagList[i].firstDate)
        }
      }
    }
    that.setData({ 
      dataList:rest.data.daySkipRopeList.records, 
      monthSkipRope:rest.data.monthSkipRope,
      daySkipRope:rest.data.daySkipRope,
      spot:dataList
      //totalPage:rest.data.totalCount 
    }) 


    // var vst  =  that.data.switchList; 
    // var dataList = [...vst[that.data.selectIndex].data.list,...rest.data.list] 
    // vst[that.data.selectIndex].data =rest.data 
    // vst[that.data.selectIndex].data.list = dataList 
     
    // that.setData({ 
    //   switchList:vst, 
    //   totalPage:rest.data.totalCount 
    // }) 
    // console.log('列表个数数据='+this.data.switchList[that.data.selectIndex].data.list.length) 
    //console.log('列表数据='+JSON.stringify(this.data.switchList)) 
  }else{ 
    wx.showToast({ 
      title: rest.errMsg||'网络异常,请重试！', 
      icon: 'none', 
      duration: 2000, 
      mask:true 
    }) 
  } 
}) 
.catch(r => { 
  console.error(r) 
  wx.showToast({ 
    title: '网络异常,请重试！', 
    icon: 'none', 
    duration: 2000, 
    mask:true 
  }) 
}) 
}, 
 
  /** 
   * 生命周期函数--监听页面初次渲染完成 
   */ 
  onReady() { 
 
  }, 
 
  /** 
   * 生命周期函数--监听页面显示 
   */ 
  onShow() { 
 
  }, 
 
  /** 
   * 生命周期函数--监听页面隐藏 
   */ 
  onHide() { 
 
  }, 
 
  /** 
   * 生命周期函数--监听页面卸载 
   */ 
  onUnload() { 
 
  }, 
 
  /** 
   * 页面相关事件处理函数--监听用户下拉动作 
   */ 
  onPullDownRefresh() { 
 
  }, 
 
  /** 
   * 页面上拉触底事件的处理函数 
   */ 
  onReachBottom() { 
 
  }, 
 
  /** 
   * 用户点击右上角分享 
   */ 
  onShareAppMessage() { 
 
  } 
})